package de.slothsoft.wasbinich.android.free;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.InterstitialAd;

import de.slothsoft.wasbinich.android.QuestionActivity;

public class QuestionAdvertizingCallBack extends QuestionActivity.CallBack {

    @Override
    public void onPictureFetched(final QuestionActivity questionActivity, int pictureIndex) {
	if (pictureIndex > 0 && pictureIndex % AdvertizingUtil.SHOW_ADS_EVERY_X_PICTURES == 0) {
	    questionActivity.pauseCountDown();
	    final InterstitialAd interstitial = AdvertizingUtil.createPopupAd(questionActivity);

	    interstitial.setAdListener(new AdListener() {
		@Override
		public void onAdLoaded() {
		    interstitial.show();
		}

		@Override
		public void onAdClosed() {
		    questionActivity.startCountDown();
		}
	    });
	}
    }
}
